package com.unlcn.ils.erpInterfaces.service.buss.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.unlcn.ils.erpInterfaces.dao.mapper.SmcitymapMapper;
import com.unlcn.ils.erpInterfaces.dao.model.Smcity;
import com.unlcn.ils.erpInterfaces.dao.model.Smcitymap;
import com.unlcn.ils.erpInterfaces.dao.model.WmsOrderException;
import com.unlcn.ils.erpInterfaces.dao.model.WmsOrderLog;
import com.unlcn.ils.erpInterfaces.service.buss.ISmcityService;
import com.unlcn.ils.erpInterfaces.service.buss.ISmcitymapService;
import com.unlcn.ils.erpInterfaces.service.buss.IWmsOrderExceptionService;
import com.unlcn.ils.erpInterfaces.service.util.BaseException;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * ERP与HYC城市映射表  服务实现类
 * </p>
 *
 * @author liangpeng
 * @since 2018-06-06
 */
@Service
public class SmcitymapServiceImpl extends ServiceImpl<SmcitymapMapper, Smcitymap> implements ISmcitymapService {

    @Autowired
    private SmcitymapMapper smcitymapMapper;

    @Autowired
    private ISmcityService smcityService;

    @Autowired
    private IWmsOrderExceptionService wmsOrderExceptionService;


    @Override
    public Long getNextIlineid() {
        return smcitymapMapper.getNextIlineid();
    }


    /**
     *  判断城市是否存在
     * @param cityName  城市名称
     * @return
     */
    @Override
    public Smcity judgeCityMap(String cityName) throws BaseException{

        if (StringUtils.isEmpty(cityName))
            return null;

        // 将城市转换为erp里的数据格式
        String city =  cityName.replace("市","");
        EntityWrapper<Smcity> ewcity = new EntityWrapper<>();
        ewcity.eq("VCCITYNAME", city);
        List<Smcity> listCity =smcityService.selectList(ewcity);
        if(CollectionUtils.isNotEmpty(listCity)){
            Smcity smcity = listCity.get(0);
            return smcity;
        }else{
            throw new BaseException("ERP中没有找到【"+cityName+"】对应城市");
        }
    }
}
